import * as components from "@/components/low-code/page-designer/pc-library/index"
import * as baseRenderComponents from "@/components/low-code/page-designer/pc-library/base-components/widget/index"
// import { LowCode } from "@/components/low-code/core"
import parse from "../parse/index.vue"
import designer from "../designer/index.vue"
/****预览所需解析器 */
import renderParse from "@/components/low-code/page-render/parse/index.vue"

// 引入动画库
import "animate.css"
//引入字体图标
// import "@/iconfont/iconfont.css"

//代码高亮文件引入
import hljs from 'highlight.js'
//样式文件,这里我选的是sublime样式，文件里面还有其他样式可供选择
import 'highlight.js/styles/monokai-sublime.css'

import "@/components/low-code/style/index.css"


/****
 * 编辑器
 */
import "./ace/ace-builds";
import codeEditor from "../components/code-editor/index.vue"

type Params = { custom: { config: any, widget: any, setting: any }[] }
const install = function (app: any, opts?: Params) {
    /****
     * 设计器所需组件
     */
    for (const [key, component] of Object.entries(components)) {
        app.component(key + 'Designer', component)
    }
    /****
     * 预览解析所需组件
     */
    for (const [key, component] of Object.entries(baseRenderComponents)) {
        app.component(key + 'Render', component)
    }
    app.component("lowCodeParse", parse)
    app.component("renderParse", renderParse)
    app.component("pageDesigner", designer)
    app.component("lowCodeEditor", codeEditor)

    app.directive('highlight', function (el: { querySelectorAll: (arg0: string) => any; }) {
        const blocks = el.querySelectorAll('pre code');
        blocks.forEach((block: HTMLElement) => {
            hljs.highlightBlock(block)
        })
    })

    /****
     * 注册自定义组件
     */
    if (opts?.custom && opts?.custom.length > 0) {
        //LowCode.custom = opts?.custom
        console.log(opts.custom)
        opts.custom.map(item => {
            app.component(item.config.type + 'WidgetDesigner', item.widget)
            app.component(item.config.type + 'SettingDesigner', item.setting)
        })
    }


}

export default install



